<template>
  <view>
    <input type="file" accept="image/*" @change="onFileChange" v-if="isH5" />
    <image :src="imageSrc" v-if="imageSrc" />
  </view>
</template>

<script>
export default {
  data() {
    return {
      isH5: process.env.VUE_APP_PLATFORM === 'h5',
      imageSrc: ''
    };
  },
  methods: {
    onFileChange(e) {
      const file = e.target.files[0];
      if (file) {
        this.imageSrc = URL.createObjectURL(file);
      }
    }
  }
};
</script>
